<?php
/**
 *
 *
 */
class Yz_Model_Field_Date
    extends Yz_Model_Field_Abstract
{



    /** Initialization value
     *  @return
     */
    public function assignValue($value)
    {
        if (null === $value)
            return $this->getDefaultValue();
        return new Yz_Date($value);
    }

    /** Select a default value
     *  @return default value
     */
    public function defaultValue()
    {
        $v = null;
        $d = $this->fetchConfig('defaultvalue');
        if ($d)
            if ('now' === strtolower($d))
                $d = null;
            $v = new Yz_Date($d);
        return $v;
    }

    /** Test if a value is a valid true/false
     *  @param mixed value
     *  @return bool
     *  @throw TypeError
     *  @throw ValueError
     *  @throw NullValueError
     */
    protected function _testValue($value)
    {
        if (! ($value instanceof Yz_Date)) {
            $value = parent::_testValue($value); // -> scalar
            if (null !== $value)
                $value = new Yz_Date($value);
        }
        return $value;
    }

}
